package com.xxx.rpc.common.xml.valueresolver;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.util.StringValueResolver;

import com.xxx.rpc.common.utils.WrapperDubboUtils;
import com.xxx.rpc.common.xml.Dubbo;


public class EmbeddedValueResolverAwareBeanPostProcessor implements BeanPostProcessor,EmbeddedValueResolverAware{

	private StringValueResolver resolver;

	@Override
	public void setEmbeddedValueResolver(StringValueResolver resolver) {
		this.resolver = resolver;
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if(beanName.equals(Dubbo.class.getName())) {
			WrapperDubboUtils.wrapper((Dubbo)bean, resolver);
		}
		return bean;
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		return bean;
	}

}
